#include <algorithm>
#include <iostream>
#include "gtest/gtest.h"
#include "SparseMatrix.h"

TEST(Matrix, GetAndSet) {
	SparseMatrix<int, double> A(10, 10);
	A.set(2, 4, 666.0);
	ASSERT_EQ(666.0, A.get(2, 4));
	A.set(1, 8, 2.0);
	ASSERT_EQ(2.0, A.get(1, 8));
	A.set(2, 4, 333.0);
	ASSERT_EQ(333.0, A.get(2, 4));
	ASSERT_EQ(0.0, A.get(5, 5));
}

TEST(Matrix, RowColCountsSizes) {
	SparseMatrix<int, int> A(4, 4);
	A.set(1, 1, 1);
	ASSERT_EQ(1, A.get_row_size(1));
	ASSERT_EQ(1, A.get_col_size(1));
	ASSERT_EQ(0, A.get_row_size(2));
	ASSERT_EQ(0, A.get_col_size(2));
	A.set(1, 2, 3);
	ASSERT_EQ(2, A.get_row_size(1));
	ASSERT_EQ(1, A.get_col_size(1));
	ASSERT_EQ(1, A.get_col_size(2));
	ASSERT_EQ(0, A.get_row_size(3));
	ASSERT_EQ(0, A.get_col_size(3));
	A.set(1, 2, 0);
	ASSERT_EQ(1, A.get_row_size(1));
	ASSERT_EQ(1, A.get_col_size(1));
	ASSERT_EQ(0, A.get_row_size(2));
	ASSERT_EQ(0, A.get_col_size(2));
	A.set(1, 2, 3);
	ASSERT_EQ(2, A.get_row_size(1));
	ASSERT_EQ(1, A.get_col_size(1));
	ASSERT_EQ(1, A.get_col_size(2));
	ASSERT_EQ(0, A.get_row_size(3));
	ASSERT_EQ(0, A.get_col_size(3));
	A.set(2, 1, 4);
	ASSERT_EQ(2, A.get_row_size(1));
	ASSERT_EQ(2, A.get_col_size(1));
	ASSERT_EQ(1, A.get_row_size(2));
	ASSERT_EQ(1, A.get_col_size(2));
}

